<?php

class duxSermodModel extends Model {
    public function __construct() {
        parent::__construct('sermod','gen','C:\opl\Datos\\');
    }
    
    public function getLastConsect($serie,$almacen = '',$empresa = 1){
        $almacen = $almacen != '' ? " AND ALMACEN = '$almacen'" : "";
        $data = $this->lista('
            SELECT CONSECUTIVO
            FROM ' . $this->getTable(true,$this->_table) . "
            WHERE EMPRESA = $empresa AND SERIE = '$serie'$almacen
        ");
        
        $this->_db->setQuery('
            UPDATE ' . $this->getTable(true) . " 
            SET CONSECUTIVO = " . ($data[0]['consecutivo'] + 1) . "
            WHERE EMPRESA = $empresa AND SERIE = '$serie'$almacen
        ");
        return $data[0]['consecutivo'];
    }
}

?>
